package com.yanqu.road.server.cmd.chefduel.process1;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChefDuelPhase1Proto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.chefduel.ChefDuelPhase1Module;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CHEF_DUEL1_ADD_ENERGY,desc = "厨神争霸一阶使用体力道具")
public class ChefDuelPhase1AddEnergyCmd extends AbstractCommand {

    private int activityId;

    private int userItemNum;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ChefDuelPhase1Proto.ChefDuelPhase1AddEnergyReq req = ChefDuelPhase1Proto.ChefDuelPhase1AddEnergyReq.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        userItemNum = req.getUseItemNum();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(ChefDuelPhase1Module.class).addEnergy(activityId, userItemNum);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            ChefDuelPhase1Proto.ChefDuelPhase1AddEnergyResp.Builder resp = ChefDuelPhase1Proto.ChefDuelPhase1AddEnergyResp.newBuilder();
            resp.setRet(ret);
            player.sendPacket(ClientProtocol.U_CHEF_DUEL1_ADD_ENERGY, resp);
        }
    }
}
